package com.hzzh.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hzzh.service.EmployeeService;

/**
 * Servlet implementation class ApproveServlet
 */
@WebServlet("/ApproveServlet")
public class ApproveServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ApproveServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		int employeeid = Integer.parseInt(request.getParameter("employeeid"));
		String oper = request.getParameter("oper");
		EmployeeService es = new EmployeeService();
		try {
			if(oper != null && oper.equals("yes")){
			    es.updateStatusService(employeeid, "1");
			    request.getRequestDispatcher("ViewAllEmployeesServlet?code=approve").forward(request, response);
			}
			if(oper != null && oper.equals("no")){
			    es.updateStatusService(employeeid, "2");
			    request.getRequestDispatcher("ViewAllEmployeesServlet?code=approve").forward(request, response);
			}
			if(oper != null && oper.equals("close")){
			    es.updateStatusService(employeeid, "2");
			    request.getRequestDispatcher("SearchEmployeesServlet").forward(request, response);
			}
		}
		catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
	}

}
